package com.example.security.funtion;

import com.example.core.utils.UserUtils;
import com.googlecode.aviator.runtime.type.AviatorBoolean;
import com.googlecode.aviator.runtime.type.AviatorObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.Map;

/***
 * @AuthMethod(expression = "CheckRoleFunction('SYS_JOB_MANAGE')")
 * 校验角色信息
 */
@Service
public class CheckRoleFunction extends SysAbstractFunction {

    Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public AviatorObject call(Map<String, Object> env, AviatorObject object) {
        String roleCode = object.stringValue(env);
        if (UserUtils.hasRole(roleCode)) {
            return AviatorBoolean.TRUE;
        }
        return AviatorBoolean.FALSE;
    }
}
